package com.lancoo.znbkxx.teacher.adapter

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.lancoo.znbkxx.teacher.model.data.ClassFlag
import kotlinx.android.synthetic.main.item_class.view.*

/**
 * @author : wealive
 * @date   : 2020/5/27 20:25
 * @desc   :
 */
class PublishClassListAdapter(
    resId: Int, data: MutableList<ClassFlag>?,
    val listener: OnCheckedClass?
) :
    BaseQuickAdapter<ClassFlag, BaseViewHolder>(resId, data) {
    override fun convert(helper: BaseViewHolder, item: ClassFlag?) {
        with((helper.itemView)) {
            cb_class.text = item!!.CourseClassName
//            apply {
//                if (item.IsRelease) {
//                    alpha = 0.1f
//                    cb_class.isEnabled = false
//                } else {
//                    alpha = 1.0f
//                    cb_class.isEnabled = true
//                }
//            }
            cb_class.setOnCheckedChangeListener { _, isChecked ->
                item.checked = isChecked
                listener?.checked()
            }
            cb_class.isChecked = item.checked
        }
    }

    fun selectAll(isAll: Boolean) {
        data.forEach {
            it.checked = isAll
        }
        notifyDataSetChanged()
    }

    interface OnCheckedClass {
        fun checked()
    }

    fun isSelectAll(): Boolean {
        var isAll = true
        data.forEach {
            if (!it.checked) isAll = false
        }
        return isAll
    }
}